package com.shrct.businessprocess.product.impl;

import com.shrct.businessprocess.product.RCBrand;
import com.shrct.businessprocess.product.RCNormalizerService;
import com.shrct.businessprocess.product.RCProductMetaType;
import com.shrct.businessprocess.product.RCProductSpecification;
import com.shrct.businessprocess.product.RCProductSpecificationCriteria;
import edu.fudan.mylang.pf.query.HQLBasedPagedQueryCriteria;
import org.hibernate.Query;
import org.springframework.beans.factory.BeanFactory;

public class RCProductSpecificationCriteriaImpl extends HQLBasedPagedQueryCriteria<RCProductSpecification> implements RCProductSpecificationCriteria {
  private String code;
  
  public String getCode() {
    return this.code;
  }
  
  public RCProductSpecificationCriteria setCode(final String code) {
    this.code = code;
    return this;			
    
  }
  
  private RCBrand brand;
  
  public RCBrand getBrand() {
    return this.brand;
  }
  
  public RCProductSpecificationCriteria setBrand(final RCBrand brand) {
    this.brand = brand;
    return this;			
    
  }
  
  private String info;
  
  public String getInfo() {
    return this.info;
  }
  
  public RCProductSpecificationCriteria setInfo(final String info) {
    this.info = info;
    return this;			
    
  }
  
  public void postInitialize() {
    BeanFactory _beanFactory = this.getBeanFactory();
    RCNormalizerService _bean = _beanFactory.<RCNormalizerService>getBean(RCNormalizerService.class);
    String _normalizeSid = _bean.normalizeSid(this.code);
    this.code = _normalizeSid;
  }
  
  private RCProductMetaType productMetaType;
  
  public RCProductMetaType getProductMetaType() {
    return this.productMetaType;
  }
  
  public RCProductSpecificationCriteria setProductMetaType(final RCProductMetaType productMetaType) {
    this.productMetaType = productMetaType;
    return this;			
    
  }
  
  protected String buildHQLFrom() {
    return " from com.shrct.businessprocess.product.impl.RCProductSpecificationImpl this ";
  }
  
  protected String buildHQLBody() {
    String hql = "where 1 = 1 ";
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCode()) ){
    	hql += " and (this.normalizedCode  LIKE :code)" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getBrand()) ){
    	hql += " and ((this.brand) = (:brand))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo()) ){
    	hql += " and ((this.name  LIKE :info) or (this.details  LIKE :info))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProductMetaType()) ){
    	hql += " and ((this.productMetaType) = (:productMetaType))" ;
    }
    return hql;
    
  }
  
  public void initOrderBys() {
    
  }
  
  protected void fillParameter(final Query query) {
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCode())){
    	query.setParameter("code",getCode()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getBrand())){
    	query.setParameter("brand",getBrand()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo())){
    	query.setParameter("info",getInfo()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProductMetaType())){
    	query.setParameter("productMetaType",getProductMetaType()) ;
    }			
    
  }
  
  protected Boolean isDistinct() {
    return false;
  }
  
  public RCProductSpecificationCriteriaImpl() {
    initOrderBys();
  }
}
